﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model.Query;

namespace HZ.Supervise.Web.Hospital
{
    //public partial class BarepriceGT : System.Web.UI.Page
    //{
     public partial class BarepriceGT : BasePage
     {
        HZ.Supervise.IBLL.IExecuteContext i = HZ.Supervise.BLLFactory.ExecuteContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlArea.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
            }
        }
        /// <summary>
        /// 根据查询条件，绑定相应的信息
        /// </summary>
        private void SetBind()
        {
            int totalCount = 0;
            DataTable dt = i.GetBarepriceGT(GetQurey(), this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwBarepriceGT.PageSize = AspNetPager1.PageSize;
            gvwBarepriceGT.DataSource = dt;
            gvwBarepriceGT.DataBind();
            DataTable dt1 = i.GetBarepriceGTTotal(GetQurey());
            this.lblResout.Text = "产品总数：" + dt1.Rows[0]["cpzs"] + "，&nbsp; 国产数量（台）：" + dt1.Rows[0]["sumgc"]
                    + string.Format("，占比：{0:P2}", dt1.Rows[0]["gcbl"]) + "，&nbsp; 进口数量（台）：" + dt1.Rows[0]["sumjk"]
                    + string.Format("，占比：{0:P2}", dt1.Rows[0]["jkbl"]) + "，&nbsp; 总采购数量（台）：" + dt1.Rows[0]["sumzs"];
        }
        private QGoodsDXSB GetQurey()
        {
            QGoodsDXSB qd = new QGoodsDXSB();
            qd.OrderDetailState = 1;
            qd.AreaID = ddlArea.SelectedAreaID;
            if (this.ddlBareprice.SelectedItem.Value.ToString() == "100")
            {
                qd.Append += string.Format(" Bareprice>=100.0000", Convert.ToInt32(ddlBareprice.SelectedValue));     
            }
            else if (this.ddlBareprice.SelectedItem.Value.ToString() == "0")
            {
                qd.Append += string.Format(" Bareprice>=0.0000", Convert.ToInt32(ddlBareprice.SelectedValue));
            }
            if (!string.IsNullOrEmpty(txtTimeFrom.Text.Trim()) && string.IsNullOrEmpty(txtTimeTo.Text.Trim()))
            {
                qd.Append += string.Format(" and SubmiTime >= '{0}'", txtTimeFrom.Text.Trim());
            }
            else if (!string.IsNullOrEmpty(txtTimeFrom.Text.Trim()) && !string.IsNullOrEmpty(txtTimeTo.Text.Trim()))
            {
                qd.Append += string.Format(" and SubmiTime >= '{0}' and SubmiTime <= '{1}'", txtTimeFrom.Text.Trim(), txtTimeTo.Text.Trim());
            }
            else if (string.IsNullOrEmpty(txtTimeFrom.Text.Trim()) && !string.IsNullOrEmpty(txtTimeTo.Text.Trim()))
            {
                qd.Append += string.Format(" and SubmiTime <= '{0}'", txtTimeTo.Text.Trim());
            }
            return qd;
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }

        protected void btnButton_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            int totalrecord = 0;
            DataTable dt = i.GetBarepriceGT(GetQurey(), 1, 0, out totalrecord);
            if (dt.Rows.Count > 0)
            {
                ExportFile.Instance.ExportData(dt, gvwBarepriceGT, this.Page);
            }
            else
            {
                HZ.Web.WebUtil.Alert("暂无导出的数据！", this.Page);
            }
        }

    }
}